package com.hushan.elevator.service;

/**
 * @Author: zzy
 * @Date: 2024/10/22 22:49
 * @Title:
 * @Version:
 * @Package: com.hushan.elevator.service
 */

import com.hushan.elevator.dto.UserAddDto;
import com.hushan.elevator.model.User;
import com.hushan.elevator.utils.exception.UserException;
import com.hushan.elevator.utils.exception.UserLoginException;

import java.time.LocalDateTime;
import java.util.List;

public interface UserService {
    User findUserByUserId(Integer userId);
    User findUserByTelNumb(String telNumb);
    User findUserByEmail(String email);

    /**
     * Add user to database.
     * <p>
     * Steps:
     * <ul>
     *     <li>1. Verify user is existed</li>
     *     <li>2. Email is valid</li>
     *     <li>3. Password is strong
     *         <ul>
     *             <li>Password length > 6</li>
     *             <li>Password type > 2</li>
     *             <li>Example: Password: q123456</li>
     *         </ul>
     *     </li>
     * </ul>
     * @param dto User data
     * @throws UserException
     *          <p>User already exists</p>
     *          <p>email invalid</p>
     *          <p>password easy</p>
     */
    void addUser(UserAddDto dto) throws UserException;
    void changePwd(User user, String pwd) throws UserException;
    void deleteUser(User user);
    void updateUser(User user) throws UserException;
    void changeUserEnableStatus(Integer userId, Boolean newStatus);

    /***
     * verify password is correct
     * @param username your username
     * @param password your password
     * @return is correct
     * @throws UserLoginException
     *      <br>User not found
     *      <br>Password error
     */
    boolean verifyUser(User user, String username, String password) throws UserLoginException;

    /***
     * authenticate user to spring security context
     * @param username correct username
     * @param password correct password
     * @return none
     */
    String authentication(String username, String password);

    void addUserDeptConnect(int userId, int deptId,int createdBy);

    void addUserRoleConnect(int userId, int roleId, int createdBy);

    List<User> findUsersByDept(Integer deptId);

    int findUserCountByDept(int id);

    void updateRole(Integer userId, Integer oldRoleId,Integer newRoleId);

    void updateDept(Integer userId, Integer oldDeptId,Integer newDeptId);

    void deleteUsers(List<User> usersByDept);
}
